@extends('admin.main')

@section('body')
    <div class="tab-wrap">
        <ul class="tab-nav nav">
            <li class="current"><a href="javascript:;">访问授权</a></li>
            {{--<li>--}}
                {{--<a href="{{urlAdmin('auth','getCategory',['group_name'=>$_GET['group_name'],'group_id'=>$_GET['group_id']])}}">分类授权</a>--}}
            {{--</li>--}}
            <li>
                <a href="{{urlAdmin('auth','getAdmin',['group_name'=>$_GET['group_name'],'group_id'=>$_GET['group_id']])}}">成员授权</a>
            </li>
            <li class="fr">
                <select name="group">
                    @if($authGroup))
                    @foreach($authGroup as $v)
                        <option value="{{urlAdmin('auth','getAccess',['group_name'=>$v['title'],'group_id'=>$v['id']])}}"
                                @if($v['id'] == $_GET['group_id']) selected @endif >{{$v['title']}}</option>
                    @endforeach
                    @else
                        <option>暂无内容</option>
                    @endif
                </select>
            </li>
        </ul>
        <div class="tab-content">
            <!-- 访问授权 -->
            <div class="tab-pane in">
                <form action="{{urlAdmin('auth','postWriteGroup')}}" enctype="application/x-www-form-urlencoded"
                      method="POST" class="form-horizontal auth-form">
                    @if(count($rules))
                        @foreach($rules as $v)
                            <dl class="checkmod">
                                <dt class="hd">
                                    <label class="checkbox"><input class="auth_rules rules_all" type="checkbox"
                                                                   name="rules[]" value="{{$v['id']}}">{{$v['title']}}
                                        管理</label>
                                </dt>
                                <dd class="bd">
                                    @if(count($v['child']))
                                        @foreach($v['child'] as $m)
                                            <div class="rule_check">
                                                <div>
                                                    <label class="checkbox">
                                                        <input class="auth_rules rules_row" type="checkbox"
                                                               name="rules[]"
                                                               value="{{$m['id']}}"/>{{$m['title']}}
                                                    </label>
                                                </div>
                                                @if(count($m['child']))
                                                    <span class="divsion">&nbsp;</span>
                                                    <span class="child_row">
                                                        @foreach($m['child'] as $n)
                                                            <label class="checkbox">
                                                            <input class="auth_rules" type="checkbox" name="rules[]"
                                                                   value="{{$n['id']}}"/>{{$n['title']}}
                                                            </label>
                                                        @endforeach
                                                    </span>
                                                @endif
                                            </div>
                                        @endforeach
                                    @endif
                                </dd>
                            </dl>
                        @endforeach
                        <input type="hidden" name="id" value="{{$_GET['group_id']}}"/>
                        <input type="hidden" name="title" value="{{$_GET['group_name']}}"/>
                        <button type="submit" class="btn submit-btn ajax-post" target-form="auth-form">确 定</button>
                        <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
                    @else
                        <span> aOh! 暂时还没有内容!</span>
                    @endif
                </form>
            </div>

            <!-- 成员授权 -->
            <div class="tab-pane"></div>

            <!-- 分类 -->
            <div class="tab-pane"></div>
        </div>
    </div>

@endsection
@section('script')
    <script type="text/javascript" src="/static/qtip/jquery.qtip.min.js"></script>
    <link rel="stylesheet" type="text/css" href="/static/qtip/jquery.qtip.min.css" media="all">
    <script type="text/javascript" charset="utf-8">
        +function ($) {
            var rules = [{{$thisGroup['rules']}}];
            $('.auth_rules').each(function () {
                if ($.inArray(parseInt(this.value, 10), rules) > -1) {
                    $(this).prop('checked', true);
                }
                if (this.value == '') {
                    $(this).closest('span').remove();
                }
            });

            //全选节点
            $('.rules_all').on('change', function () {
                $(this).closest('dl').find('dd').find('input').prop('checked', this.checked);
            });
            $('.rules_row').on('change', function () {
                $(this).closest('.rule_check').find('.child_row').find('input').prop('checked', this.checked);
            });

            $('.checkbox').each(function () {
                $(this).qtip({
                    content: {
                        text: $(this).attr('title'),
                        title: $(this).text()
                    },
                    position: {
                        my: 'bottom center',
                        at: 'top center',
                        target: $(this)
                    },
                    style: {
                        classes: 'qtip-dark',
                        tip: {
                            corner: true,
                            mimic: false,
                            width: 10,
                            height: 10
                        }
                    }
                });
            });

            $('select[name=group]').change(function () {
                location.href = this.value;
            });
        }(jQuery);
    </script>
@endsection
